package middleware

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

func CheckAuth(c *gin.Context) {
	userName, ok1 := c.Get("user_name")
	userID, ok2 := c.Get("user_id")

	if !ok1 || !ok2 {
		c.JSON(401, gin.H{
			"code": 401,
			"msg":  "未授权访问",
		})
		c.Abort()
		return
	}

	fmt.Printf("user_name:%v, user_id:%v\n", userName, userID)
	c.Next()
}
